package cn.aruan.test;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.CyclicBarrier;

import cn.aruan.dcp.service.Echo;

import com.alibaba.dubbo.common.utils.ConfigUtils;
import com.alibaba.dubbo.rpc.benchmark.AbstractClientRunnable;
import com.alibaba.dubbo.rpc.benchmark.ServiceFactory;

public class MyBenchmarkClientRunnable extends AbstractClientRunnable {
	String message;
	public MyBenchmarkClientRunnable(String targetIP, int targetPort,
			int clientNums, int rpcTimeout, CyclicBarrier barrier,
			CountDownLatch latch, long startTime, long endTime) {
		super(targetIP, targetPort, clientNums, rpcTimeout, barrier, latch,
				startTime, endTime);
		Object o = ConfigUtils.getProperties().get("echomessage");
		message = o == null?"hello, world!":o.toString();
	}

	@SuppressWarnings({ "unchecked", "rawtypes" })
	@Override
	public Object invoke(ServiceFactory serviceFactory) {
		Echo demoService = (Echo) serviceFactory
				.get(Echo.class);
//		HeadersProvider provider = (HeadersProvider) demoService;
//		provider.getHeaders().put("cookie", "iamsorry");
//		provider.getHeaders().put("codec", "neg,gzip");
		return demoService.echo(message);
	}
}
